<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <script type="text/javascript" charset="UTF-8">
            window.onload = function(){
                
                document.getElementById('start1').onclick = function(){
                    var beginat = (new Date()).getTime();
                    var result = 0;
                    for(var i = 0; i < 1000000; i++){
                        result += i;
                    }
                    var endat = (new Date()).getTime();
                    document.getElementById('area').innerHTML = (endat - beginat).toString();
                };
                
                document.getElementById('start2').onclick = function(){
                    var code = [
                        'var result = 0;',
                        'for(var i = 0; i < 1000000; i++){',
                            'result += i;',
                        '}'
                    ].join('\n');
                    var beginat = (new Date()).getTime();
                    eval(code);
                    var endat = (new Date()).getTime();
                    document.getElementById('area').innerHTML = (endat - beginat).toString();
                };
                
                document.getElementById('start3').onclick = function(){
                    var code = [
                        'var result = 0;',
                        'for(var i = 0; i < 1000000; i++){',
                            'result += i;',
                        '}'
                    ].join('\n');
                    var beginat = (new Date()).getTime();
                    eval('function calcEval() {' + code + '}');
                    calcEval();
                    var endat = (new Date()).getTime();
                    document.getElementById('area').innerHTML = (endat - beginat).toString();
                };

            };
        </script>
        <title>JavaScriptテスト</title>
    </head>
    <body>
        <button id="start1">start1</button>
        <button id="start2">start2</button>
        <button id="start3">start3</button>
        <div id="area"></div>
        <a href="http://as-is.net/blog/archives/001362.html">元記事</a>
        <a href="http://muumoo.jp/news/2008/09/07/0evalbench.html">元々記事</a>
    </body>
</html>
